package com.cuit.dashboard.system.handler;

import com.cuit.dashboard.common.exception.GlobalException;
import com.cuit.dashboard.common.util.Result;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @program: hulu-dashboard
 * @description: 全局异常捕获
 * @author: KamTang
 * @create: 2022-06-08 17:04
 **/
@RestControllerAdvice(basePackages = "com.cuit.zuke.system.controller")
public class GlobalExceptionHandler {

    @ExceptionHandler(value = GlobalException.class)
    public Result handleGlobalException(GlobalException e) {
        return Result.error(e.getCode(), e.getMsg());
    }

    /**
     * 对于无法精确匹配的异常进行处理
     * @param throwable
     * @return
     */
    //@ExceptionHandler(value = Throwable.class)
    //public Result handleUnknownException(Throwable throwable) {
    //    return Result.error(BizCodeEnum.UNKNOWN_EXCEPTION.getCode(), BizCodeEnum.UNKNOWN_EXCEPTION.getMsg());
    //}
}
